﻿using System.Collections.Generic;
using System.Globalization;
using P2.Framework.BOLBase;
using P2.Framework.Helper;
using System.Collections.ObjectModel;
using System.Data;
using System.ComponentModel;
using Microsoft.Practices.Composite.Events;
using System;
namespace P2.SimpleAccounting.Modules.FiFiscalYear
{
    public class FiFiscalYearsFindPresenter : INotifyPropertyChanged, IFiFiscalYearsFindPresenter
    {
        public FiFiscalYearsFindPresenter(IFiFiscalYearsFindView view, Services.IFiFiscalYearService service)
        {
            View = view;
            this.Model = new BusinessEntities.FiFiscalYear();
            this.Service = service;
            
            
            View.Presenter = this;
            Model.PropertyChanged += OnModelPropertyChangedEvent;
            View.FiFiscalYearFind += new EventHandler<DataEventArgs<BusinessEntities.FiFiscalYear>>(this.OnFiFiscalYearFind);
            View.FiFiscalYearAdd += new EventHandler<DataEventArgs<BusinessEntities.FiFiscalYear>>(this.OnFiFiscalYearAdd); ;
            View.FiFiscalYearClear += new EventHandler<DataEventArgs<BusinessEntities.FiFiscalYear>>(this.OnFiFiscalYearClear); ;
            

            //Model.FiscalYearStartDate = 
            //Model.FiscalYearEndDate =


        }
        public IFiFiscalYearsFindView View { get; set; }

        public BusinessEntities.FiFiscalYear Model { get; set; }
        public List<P2TransactionMessage> MessageStack = new List<P2TransactionMessage>();
        
        
        public Services.IFiFiscalYearService Service;
        public event EventHandler<DataEventArgs<BusinessEntities.FiFiscalYear>> FiFiscalYearFind = delegate { };
        public event EventHandler<DataEventArgs<BusinessEntities.FiFiscalYear>> FiFiscalYearAdd = delegate { };

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion


        private void OnModelPropertyChangedEvent(object sender, PropertyChangedEventArgs e)
        {
            PropertyChangedEventHandler Handler = PropertyChanged;
            if (Handler != null) Handler(sender, e);

        }
        public void OnFiFiscalYearAdd(object sender, DataEventArgs<BusinessEntities.FiFiscalYear> e)
        {
            if (FiFiscalYearAdd != null)
                FiFiscalYearAdd(sender, e);
        }

        public void OnFiFiscalYearFind(object sender, DataEventArgs<BusinessEntities.FiFiscalYear> e)
        {
            if (FiFiscalYearFind != null)
                FiFiscalYearFind(sender, e);
        }
        public void OnFiFiscalYearClear(object sender, DataEventArgs<BusinessEntities.FiFiscalYear> e)
        {
            e.Value.FiscalYearName = "";
                        
            //FiscalYearStartDate
            //FiscalYearEndDate
        }

    }
}